a= input ()
 
if len(str(a)) != 4:
    print(0)
else:
    pr = False
    for length in range(4, 0, -1):
        if pr:
            break
        for i in range(4 - length + 1):
            c = int(str(a)[i:i+length])
            if c < 2:
                continue
            for j in range(2, int(c**0.5) + 1):
                if c % j == 0:
                    break
            else:
                print(c)
                pr = True
                break
    if not pr:
        print(0)
